package com.demo.oauth.server.security.authorizationcode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.code.RandomValueAuthorizationCodeServices;
import org.springframework.stereotype.Component;

import com.demo.oauth.server.model.AuthenticationCode;
import com.demo.oauth.server.service.AuthenticationCodeService;

@Component
public class DemoAuthorizationCodeService extends RandomValueAuthorizationCodeServices {

	@Autowired
	private AuthenticationCodeService authenticationCodeService;

	@Override
	protected void store(String codeValue, OAuth2Authentication authentication) {
		AuthenticationCode code = new AuthenticationCode();
		code.setCode(codeValue);
		authenticationCodeService.insert(code);

	}

	@Override
	protected OAuth2Authentication remove(String code) {
		authenticationCodeService.remove(code);
		return null;
	}

}
